/*
 * M2ResourceManager.java
 * 
 *  author: Daniel Rudigier
 *    date: 07.12.2008
 * 
 * 
 */
package at.momberban2.me.game;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.lcdui.Image;

import de.enough.polish.util.Arrays;
import de.enough.polish.util.HashMap;

import at.momberban2.me.gamecontext.M2Map;
import at.syncme.framework.midp.ResourceManager;

/**
 * a simple resource manager which collects some usually thrown
 * exceptions from images etc.
 * 
 * @author Daniel Rudigier
 *
 */
public class M2ResourceManager extends ResourceManager {
    private HashMap maps = new HashMap();

    /**
     * override the constructor
     * 
     * @return instance
     */
    public static Object getInstance() {
        if (instance == null) {
            instance = new M2ResourceManager();
        }
        
        return instance;
    }
        
    /**
     * load an map
     * 
     * @param name
     * @param location
     * @return
     */
    public M2Map loadMap(String name, String location) {
        M2Map ret = (M2Map) maps.get(name);
        
        if (ret == null) {
            ret = new M2Map(name, location);
            this.maps.put(name, ret);
        }
        
        return ret;
    }
    
    /**
     * get all maps
     * 
     * @return
     */
    public M2Map[] getMaps() {
        M2Map[] ret = new M2Map[this.maps.size()];
        Arrays.cast(this.maps.values(), ret);
        return ret;
    }

    
    
    /**
     * get a system resource
     * 
     * @param source 
     * @return
     */
    public InputStream getResource(String source) {
        return M2Midlet.class.getResourceAsStream(source);
    }


}
